package com.dup.jxlh.admin.controller;

import com.dup.jxlh.admin.entities.auth.AuthUser;
import com.dup.jxlh.admin.service.DictionaryDataService;
import com.dup.jxlh.admin.service.OrganService;
import com.dup.jxlh.api.entities.CommonResult;
import com.dup.jxlh.api.enums.ResultEnum;
import com.dup.jxlh.api.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/data")
@Validated
public class DataDictionaryController {
    @Autowired
    private DictionaryDataService dataDictionaryService;

    @Autowired
    private OrganService organService;

    @PostMapping("/getLevelData")
    public CommonResult getLevelData() {
        return ResultUtil.result(ResultEnum.SUCCESS, dataDictionaryService.getLevelData());
    }

    @PostMapping("/getContractTypeData")
    public CommonResult getContractTypeData() {
        return ResultUtil.result(ResultEnum.SUCCESS, dataDictionaryService.getContractTypeData());
    }

    @PostMapping("/getCompanyData")
    public CommonResult getCompanyData(@AuthenticationPrincipal AuthUser authUser) {
        return ResultUtil.result(ResultEnum.SUCCESS, dataDictionaryService.getCompanyData(authUser.getCompanyId()));
    }

    @PostMapping("/getDepartmentData")
    public CommonResult getDepartmentData(@AuthenticationPrincipal AuthUser authUser) {
        if (!authUser.getLevel().equals(1)) {
            return ResultUtil.result(ResultEnum.SUCCESS, dataDictionaryService.getDepartmentById(authUser.getDepartmentId()));
        }
        return ResultUtil.result(ResultEnum.SUCCESS, dataDictionaryService.getDepartmentData(authUser.getCompanyId()));
    }

    @PostMapping("/getRoleData")
    public CommonResult getRoleData(@AuthenticationPrincipal AuthUser authUser) {
        return ResultUtil.result(ResultEnum.SUCCESS, dataDictionaryService.getRoleData(authUser.getCompanyId()));
    }

    @PostMapping("/getOrganData")
    public CommonResult getOrganData(@AuthenticationPrincipal AuthUser authUser) {
        return ResultUtil.result(ResultEnum.SUCCESS, organService.getOrganList(authUser.getCompanyId()));
    }

    @PostMapping("/getChapterApplyStatusData")
    public CommonResult getChapterApplyStatusData() {
        return ResultUtil.result(ResultEnum.SUCCESS, dataDictionaryService.getChapterApplyStatusData());
    }

    @PostMapping("/getChapterApplyTypeData")
    public CommonResult getChapterApplyTypeData() {
        return ResultUtil.result(ResultEnum.SUCCESS, dataDictionaryService.getChapterApplyTypeData());
    }

    @PostMapping("/getChapterTypeData")
    public CommonResult getChapterTypeData() {
        return ResultUtil.result(ResultEnum.SUCCESS, dataDictionaryService.getChapterTypeData());
    }

    @PostMapping("/getAdminData")
    public CommonResult getAdminData(@AuthenticationPrincipal AuthUser authUser) {
        return ResultUtil.result(ResultEnum.SUCCESS, dataDictionaryService.getAdminData(authUser.getCompanyId()));
    }
}
